package com.cumulus.ianerp.ian.auth.emp.service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cumulus.ianerp.ian.auth.emp.dao.EmpDao;
import com.cumulus.ianerp.ian.auth.emp.domain.Emp;
import com.cumulus.ianerp.ian.util.format.MD5Utils;
/**
 * 用户的service层
 * @author Ian
 * @date 2017-05-13
 *
 */
@Service
public class EmpService {
	
	@Autowired
	private EmpDao empDao;
	/**
	 * 查找用户是否存在
	 * 存在返回true
	 * 不存在返回false
	 * @author Ian
	 * @date 2017-05-13
	 * @param emp
	 * @return
	 */
	public boolean empLogin(Emp emp,HttpSession session) {
		
		String md5Pwd=MD5Utils.md5(emp.getPwd());
		Emp empService=empDao.findUser(emp.getUserName());
		String dbPwd=empService.getPwd();
		if(empService!=null){
			if(dbPwd.equals(md5Pwd)){
				session.setAttribute("emp", empService);
				return true;
			}
		}
		return false;
	}

}
